<template>
    <div class="warning-rule">
        <div class="table">
            <el-table :data="tableData" border fit style="width: 100%" header-cell-class-name="table-header-cell"
            :class="tableData.length === 0 ? 'table-empty' : ''" v-loading="loading" @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column
                label="序号"
                type="index"
                width="80">
              </el-table-column>
              <el-table-column label="规则编号" align="center" prop="ruleNumber" />
              <el-table-column label="预警名称" align="center" prop="name" />
              <el-table-column label="预警数据源" align="center" prop="sourceDataType" >
                <template slot-scope="scope">
                  <span v-if="scope.row.sourceDataType == '1'">就诊数据预警</span>
                  <span v-else >医疗机构数据预警</span>
                </template>
              </el-table-column>
              <el-table-column label="预警总数" align="center" prop="total" />
            <el-table-column label="预警开关" align="center" prop="enabled">
              <template slot-scope="scope">
                  <div class="whitelist">
                    <el-switch
                      v-model="scope.row.enabled=='0'?false:true"
                      active-color="#13ce66"
                      inactive-color="#ff4949"
                      @change="enableds(scope)"
                    >
                    </el-switch>
                  </div>
              </template>
            </el-table-column>
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <!-- <template slot-scope="scope">
                   <el-button
                     size="mini"
                     type="text"
                     icon="el-icon-search"
                     @click="handleUpdate(scope.row)"
                   >查看</el-button>
                 </template>-->
                <template slot-scope="scope">
                  <el-button
                    size="mini"
                    type="text"
                    @click="handleView(scope)"
                  >查看</el-button>
                </template>
              </el-table-column>
            </el-table>
        </div>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <RuleGroup :visible.sync="operationModalVisible" :tableData="ruleGroupData"></RuleGroup>
    </div>
</template>
<script>
import { listType } from "@/api/system/type";
import RuleGroup from '@/views/maintenance/pages/warning-rule/components/rule-group/index.vue'

export default {
  name: 'WarningRule',
  components: {
    RuleGroup
  },
  data() {
      return {
        operationModalVisible: false,
        ruleGroupData: [{
          name:'计划生育预警',
          count:'3条',
          source:'处方数据',
          desc:'计划生育预警',
          ruleDetails: [
            {
              name: '关键词规则',
              type: '医院编号',
              priority: 30,
              keywordData: [{
                order: 1,
                type: '诊疗科目',
                name: '计划生育专业',
                condition: '无',
              }]
            },
            {
              name: '诊疗科目规则',
              type: '诊疗科目',
              priority: 20,
              subjectData: [
                {
                  order: 1,
                  type: '诊疗科目',
                  subject: '计划生育专业',
                  condition: '无',
                }
              ]
            },
            {
              name: '关键字规则',
              type: '药品/醒目名称',
              priority: 10,
              keyword1Data: [
                {
                  order: 1,
                  type: '药品/项目名称',
                  keyword: '皮理',
                  condition: '包含',
                },
                {
                  order: 2,
                  type: '宫内节育器',
                  keyword: '皮理',
                  condition: '包含',
                },
              ]
            }
          ]
        }],
        // 遮罩层
        loading: false,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        dockorList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          ruleNumber: null,
          time: null,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
        },
        tableData: [
          {
            ruleNumber:12,
          }
        ]
      }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listType(this.queryParams).then(response => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    handleView(scope){
      this.operationModalVisible = true
    },
    jupPage(row){
      console.log(row)
      if (row.name === '校验逾期预警'){
        this.$router.push({
          path: '/riskList/VerifyWarning',
        })
      }else if (row.name === '执业许可证逾期预警'){
        this.$router.push({
          path: '/riskList/licenseOver',
        })
      }else if (row.name === '儿科超范围预警'){
        this.$router.push({
          path: '/riskList/childBeyond',
        })
      }else if (row.name === '无抗菌药物处方权预警'){
        this.$router.push({
          path: '/riskList/noRightKj',
        })
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        hospitalid: null,
        sex: null,
        idcard: null,
        parcticescope: null,
        parcticelevel: null,
        parcticeclass: null,
        qualification: null,
        doctorlicence: null,
        workcpet: null,
        antecedent: null,
        specialty: null,
        unit: null,
        organname: null,
        regionname: null,
        createtime: null,
        updatetime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getDockor(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDockor(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDockor(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项？').then(function() {
        return delDockor(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$modal.confirm('是否确认导出所有【请填写功能名称】数据项？').then(() => {
        this.exportLoading = true;
        return exportDockor(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    }
  }
}
</script>
<style scoped lang="scss">
.warning-rule {
    height: 100%;
    display: flex;
    flex-direction: column;
}
.table {
    flex: 1;
    background-color: #fff;
    margin: 13px 0 16px;

    ::v-deep .table-header-cell {
        background-color: #EBEFF8;
        padding-left: 21px;
        font-weight: 500;
        font-size: 16px;
        color: #414141;
    }

    .el-table {
        height: 100%;
    }

    ::v-deep .el-table__cell {
        padding-left: 21px;
        font-weight: 500;
        font-size: 16px;
        color: #414141;
    }

    :v-deep .el-table__body-wrapper {
        height: 100%;
    }

    :v-deep .el-table__empty-block {
        height: 100%;
    }

    .operation {
        display: flex;
        align-items: center;
        height: 100%;

        .view {
            cursor: pointer;
            font-weight: 500;
            font-size: 16px;
            color: #414141;
            height: 16px;
            line-height: 16px;
            background-repeat: no-repeat;
            background-position: 0 center;
            margin-right: 20px;
            user-select: none;
        }
    }
}
</style>
